import android.view.View
import androidx.viewpager2.widget.ViewPager2

class TransFormer : ViewPager2.PageTransformer {
    var MIN_ALPHA = 0.5f
    var MIN_SCALE = 0.8f
    private val scaleValue = 0.7f // 设置缩放因子
    override fun transformPage(page: View, position: Float) {
        val absPosition = Math.abs(position)
        if (absPosition > 4) {
            // 超过4个项目的位置，完全隐藏
            page.alpha = 0f
        } else {
            // 在可见范围内的项目
            page.alpha = 1f
            // 缩放
            val scaleFactor = scaleValue + (1 - scaleValue) * (1 - absPosition)
            page.scaleX = scaleFactor
            page.scaleY = scaleFactor
        }
    }
}
